$CertusJsonAjax.ajax("zdbxlcById", {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.receptionTribursementEntity = res.data;

    $$scope.receptionTribursementEntity.invoiceTime = $$filter("date")($$scope.receptionTribursementEntity.invoiceTime, "yyyy-MM-dd");
    $$scope.receptionTribursementEntity.receptionTime = $$filter("date")($$scope.receptionTribursementEntity.receptionTime, "yyyy-MM-dd");
    $$scope.receptionTribursementStepEntity = {
        "processInstanceId": $CertusJsonAjax.getProInstanceId(),
        "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
    }
    $$scope.processCCBXTrace = res.data.processs;

    $$scope.rmb = upDigit($$scope.receptionTribursementEntity.receptionStandard);
});


$$scope.getsssbbb = function(bb){
    ;
    //starting denied sentback others completed
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
         return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}
/*//客户 公司 code
$$scope.$watch("receptionTribursementEntity.customUnitName", function (newValue, old, scope) {
    if (old && newValue) {
        if (newValue.indexOf(old) > -1) {
            cusProjName = newValue;
            scope.dataList.cusCompSelect = scope.dataList.cusCompSelect.filter(isSaveCusName);
            if (scope.dataList.cusCompSelect.length) {
                if (scope.dataList.cusCompSelect.length == 1) {
                    scope.receptionTribursementEntity.customUnitId = scope.dataList.cusCompSelect[0].id;
                    scope.receptionTribursementEntity.customUnitName = scope.dataList.cusCompSelect[0].comName;
                }
            }
            return;
        }
    }
    //直接去数据库 查询
    $CertusFormAjax.ajax("cusCompanyNameSelect", {cusName: newValue}, function (res) {
        scope.dataList.cusCompSelect = res.data;
        if (scope.dataList.cusCompSelect.length) {
            if (scope.dataList.cusCompSelect.length == 1) {
                scope.receptionTribursementEntity.customUnitId = scope.dataList.cusCompSelect[0].id;
                scope.receptionTribursementEntity.customUnitName = scope.dataList.cusCompSelect[0].comName;
            }
        }
    })
})
//监听项目名称
$$scope.$watch("receptionTribursementEntity.projName", function (newValue, old, scope) {
    if (old && newValue) {
        if (newValue.indexOf(old) > -1) {
            nowProjName = newValue;
            scope.dataList.projNameSelect = scope.dataList.projNameSelect.filter(isSaveProjName);
            if (scope.dataList.projNameSelect.length) {
                if (scope.dataList.projNameSelect.length == 1) {
                    scope.receptionTribursementEntity.projId = scope.dataList.projNameSelect[0].projId;
                    scope.receptionTribursementEntity.projName = scope.dataList.projNameSelect[0].projName;
                }
            }
            return;
        }
    }

    //直接去数据库 查询
    $CertusFormAjax.ajax("relatedProj", {param: newValue}, function (res) {
        scope.dataList.projNameSelect = res.data;
        if (scope.dataList.projNameSelect.length) {
            if (scope.dataList.projNameSelect.length == 1) {
                scope.receptionTribursementEntity.projId = scope.dataList.projNameSelect[0].projId;
                scope.receptionTribursementEntity.projName = scope.dataList.projNameSelect[0].projName;
            }
        }
    })
})*/

$$scope.dataList = {}

$$scope.dataList.companySelect = [
    {name: "赛特斯集团", code: "STSJT"},
    {name: "赛特斯广东", code: "STSGD"},
    {name: "赛特斯南京", code: "STSNJ"},
    {name: "赛特斯北京", code: "STSBJ"},
    {name: "赛特斯上海", code: "STSSH"},
    {name: "融合运维事业部", code: "SYB-RX"},
    {name: "浩方科技", code: "HFKJ"},
    {name: "浩方信息", code: "HFXX"}
]

//同意 提交
$$scope.zdbxSubmit = function () {
    $CertusJsonAjax.ajax("zdbxlcProjApproval", $$scope.receptionTribursementStepEntity, function (res) {
        if (res.data == "success") {
            findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
            history.back();
            return;
        }
        layer.msg("提交过程中遇到错误");
    })
}


$$scope.zdbxlcProjVeto = function () {
    $CertusJsonAjax.ajax("zdbxlcProjVeto", $$scope.receptionTribursementStepEntity, function (res) {
        if (res.data == "success") {
            // findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
            layer.msg("已退回至起草人");
            history.back();
            return;
        }
        layer.msg("提交过程中遇到错误");
    })
}

$$scope.zdbxlcProjDenied = function () {
    $CertusJsonAjax.ajax("zdbxlcProjDenied", $$scope.receptionTribursementStepEntity, function (res) {
        if (res.data == "success") {
            findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
            history.back();
            return;
        }
        layer.msg("提交过程中遇到错误");
    })
}


// RMB大写转换
function upDigit(n) {
    var fraction = ['角', '分'];
    var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
    var unit = [
        ['元', '万', '亿'],
        ['', '拾', '佰', '仟']
    ];
    var head = n < 0 ? '欠' : '';
    n = Math.abs(n);

    var s = '';

    for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
    }
    s = s || '整';
    n = Math.floor(n);

    for (var i = 0; i < unit[0].length && n > 0; i++) {
        var p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++) {
            p = digit[n % 10] + unit[1][j] + p;
            n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
    }
    return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
}



//提交流程
$$scope.zdbxlcSubmit = function(){
    if(certusValidateNotnull()){
        /*if(!$$scope.receptionTribursementEntity.customUnitId){
            layer.msg("客户单位未填写");
            return;
        }*/

        if(!$$scope.receptionTribursementEntity.projId){
            layer.msg("项目未填写");
            return;
        }
        $$scope.receptionTribursementStepEntity = {
            "processInstanceId": $CertusJsonAjax.getProInstanceId(),
            "stepInstanceId": $CertusJsonAjax.getStepInstanceId(),
            receptionTribursementEntity:$$scope.receptionTribursementEntity
        };
        $CertusJsonAjax.ajax("zdbxlcSubmitSecond",$$scope.receptionTribursementEntity,function(res){
            if(res.data == "success"){

                findBacklogPersonHead($CertusFormAjax, "ZDBXLC");
                window.history.back();
                return;
            }
            layer.msg("提交遇到错误")
        })
    }
}

$$scope.zdbxlcKJHKApproval = function(){
    $CertusJsonAjax.ajax("zdbxlcKJHKApproval", $$scope.receptionTribursementStepEntity, function (res) {
        if (res.data == "success") {
            findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
            history.back();
            return;
        }
        layer.msg("提交过程中遇到错误");
    })
}
//财务经理 提交
$$scope.zdbxlcCWJLApproval = function(){
    $CertusJsonAjax.ajax("zdbxlcCWJLApproval", $$scope.receptionTribursementStepEntity, function (res) {
        if (res.data == "success") {
            findBacklogPerson($CertusFormAjax, $CertusJsonAjax.getStepInstanceId());
            history.back();
            return;
        }
        layer.msg("提交过程中遇到错误");
    })
}